package com.bank.trade_records.zhuan_money.service.impl;


import com.bank.trade_records.qu_money.entity.QuMoney;
import com.bank.trade_records.zhuan_money.dao.ZhuanMoneyDao;
import com.bank.trade_records.zhuan_money.entity.ZhuanMoney;
import com.bank.trade_records.zhuan_money.service.ZhuanMoneyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class ZhuanMoneyServiceImpl implements ZhuanMoneyService {

    @Autowired
    private ZhuanMoneyDao zhuanMoneyDao;

    @Override
    public ZhuanMoney getZhuanMoneyById(Long id) {
        return zhuanMoneyDao.selectById(id);
    }

    @Override
    @Transactional
    public boolean addZhuanMoney(ZhuanMoney ZhuanMoney) {
        return zhuanMoneyDao.insert(ZhuanMoney) > 0;
    }

    @Override
    @Transactional
    public boolean updateZhuanMoney(ZhuanMoney ZhuanMoney) {
        return zhuanMoneyDao.updateById(ZhuanMoney) > 0;
    }

    @Override
    @Transactional
    public boolean deleteZhuanMoneyById(Long id) {
        return zhuanMoneyDao.deleteById(id) > 0;
    }

    @Override
    public List<ZhuanMoney> getAllZhuanMoneys() {
        return zhuanMoneyDao.selectList(null);
    }

    @Override
    @Transactional
    public boolean batchInsert(List<ZhuanMoney> zhuanMoneyList) {
        return zhuanMoneyDao.insertBatchSomeColumn(zhuanMoneyList) > 0; // MyBatis-Plus提供了批量插入的方法
    }

    @Override
    public Page<ZhuanMoney> getZhuanMoneyPage(Page<ZhuanMoney> ZhuanMoneyPage) {
        return zhuanMoneyDao.selectPage(ZhuanMoneyPage, null);
    }

    public List<ZhuanMoney> getZhuanMoneyListByAccountId(long accountId){
        QueryWrapper<ZhuanMoney> zhuanMoneyQueryWrapper=new QueryWrapper<>();
        zhuanMoneyQueryWrapper.eq("account_id", accountId);
        return zhuanMoneyDao.selectList(zhuanMoneyQueryWrapper);
    }
    public List<Object> getDailyTransactionAmounts() {
        List<Map<String, Object>> daoResult = zhuanMoneyDao.getDailyTransactionAmounts();
        System.out.println(daoResult);
        List<Object> totalAmounts = new ArrayList<>();
        totalAmounts.add("转账记录");
        for (Map<String, Object> map : daoResult) {
            Double totalAmount = (Double) map.get("total_amount");
            totalAmounts.add(totalAmount);
        }

        return totalAmounts;
    }



}